<template>
  <div class="app-container">
    <!-- 顶部搜索 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item label="年度" prop="nd">
        <el-input size="mini"
                  v-model="queryParams.nd"
                  placeholder="请输入年度"
                  clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="软件名称" prop="rjName">
        <el-input size="mini"
                  v-model="queryParams.rjName"
                  placeholder="请输入软件名称"
                  clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="著作权人" prop="zzqr">
        <el-input size="mini"
                  v-model="queryParams.zzqr"
                  placeholder="请输入著作权人"
                  clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="主要完成人" prop="zyWcR">
        <el-input size="mini"
                  v-model="queryParams.zyWcR"
                  placeholder="请输入主要完成人"
                  clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="编程语言" prop="bcYy">
        <el-input size="mini"
                  v-model="queryParams.bcYy"
                  placeholder="请输入编程语言"
                  clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开发方式" prop="kfFs">
        <el-select size="mini" v-model="queryParams.kfFs" placeholder="请选择开发方式" clearable>
          <el-option
            v-for="dict in dict.type.zscq_rzgl_kffs"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="申请单位" prop="sqDw">
        <el-select size="mini" v-model="queryParams.sqDw" placeholder="请选择申请单位" clearable>
          <el-option
            v-for="dict in dict.type.xmgl_lxwj_pzdw"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="流程状态:" prop="processStatus">
        <el-select v-model="queryParams.processStatus" placeholder="请选择流程状态" clearable size="mini">
          <el-option
            v-for="dict in dict.type.process_business_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 顶部按钮 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['rzgl:rzsq:export']"
        >导出Excel
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- 表格 -->
    <el-table @row-click="clickRow" ref="table" highlight-current-row
              :header-cell-style="{background:'#d0cece',color:'#000000',fontWeight:'bold'}"
              v-loading="loading" :data="rzsqList" @selection-change="handleSelectionChange">
      <!--      <el-table-column type="selection" width="55" align="center"/>-->
      <el-table-column label="序号" align="center" type="index" :index="indexMethod"/>
      <el-table-column show-overflow-tooltip label="年度" align="center" prop="nd" width="70"/>
      <el-table-column show-overflow-tooltip label="软件名称" align="center" prop="rjName">
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="handleButtonClick(scope.row)"
          >
            <el-link type="primary">{{ scope.row.rjName }}</el-link>
          </el-button>
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip label="著作权人" align="center" prop="zzqr"/>
      <el-table-column show-overflow-tooltip label="主要完成人" align="center" prop="zyWcR"/>
      <el-table-column show-overflow-tooltip label="编程语言" align="center" prop="bcYy"/>
      <el-table-column show-overflow-tooltip label="开发方式" align="center" prop="kfFs">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.zscq_rzgl_kffs" :value="scope.row.kfFs"/>
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip label="申请单位" align="center" prop="sqDw">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.xmgl_lxwj_pzdw" :value="scope.row.sqDw"/>
        </template>
      </el-table-column>
      <el-table-column label="证书查看" align="center" >
        <template slot-scope="scope">
          <el-button
            type="primary"
            size="mini"
            @click="handleZsCkClick(scope.row)"
          >查看
          </el-button>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="processStatus" width="120">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.process_business_status" :value="scope.row.processStatus" />
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-if="scope.row.processStatus==1 || scope.row.processStatus==4"
            v-hasPermi="['rzgl:rzsq:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-if="scope.row.processStatus==1 || scope.row.processStatus==4"
            v-hasPermi="['rzgl:rzsq:remove']"
          >删除
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleJinDu(scope.row)"
            v-if="scope.row.processStatus !== 1"
          >查询进度</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页组件 -->
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 查询进度 -->
    <Jindu ref="picture"/>

    <!-- 软著详情 -->
    <RzXq ref="rzXq"/>

    <!-- 根据rzsqId查询符合条件的软件授权登记列表 -->
    <RjSqDjList ref="rjSqDjList"/>
  </div>
</template>

<script>
import {
  listRzsq
} from "@/api/zscq/rzgl/rzsq";
import {getToken} from "@/utils/auth";
import Jindu from "@/views/components/liuChengState/jindu.vue";
import RzXq from "@/views/zscq/rzgl/rzsq/components/RzXq.vue";
import RjSqDjList from "@/views/zscq/rzgl/components/RjSqDjList.vue";

export default {
  name: "Rzsq",
  components: {RjSqDjList, RzXq, Jindu},
  dicts: ['xmgl_lxwj_pzdw', 'zscq_rzgl_kffs', 'process_business_status'],
  data() {
    return {
      xg: false, //判断是新增还是修改 (false新增 true修改)
      allFilesUploaded: false, // 添加这个来追踪所有文件是否上传完成
      fjUpload: false, //附件上传弹窗
      //要修改的 软著申请id
      rzsqIdEdit: "",
      uploadFileUrl: process.env.VUE_APP_BASE_API + "/common/upload", // 上传文件服务器地址
      fileList: [],
      headers: {Authorization: "Bearer " + getToken()},
      number: 0,
      uploadList: [],
      fileType: ["doc", "xls", "ppt", "txt", "pdf", "docx", "zip"],
      getRzSqId: null, //从后端获取到的软著申请主键ID (UUID)
      activeName: 'jbzl', //初始打开的标签页
      selectedRow: null, // 保存当前选中的行
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedRzglRzsqFj: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 软著申请表格数据
      rzsqList: [],
      // 附件资料表格数据
      rzglRzsqFjList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        nd: null,
        rjName: null,
        zzqr: null,
        zyWcR: null,
        kjryId: null,
        bcYy: null,
        kfFs: null,
        sqDw: null,
        xmsbId: null,
        kyXm: null,
        userId: null,
        deptId: null,
        processStatus: null
      },
      // 表单参数
      form: {},

    };
  },
  created() {
    this.getList();
  },
  methods: {
    //证书查看
    handleZsCkClick(row) {
      this.$refs.rjSqDjList.handleOpen(row)
    },
    //打开软著申请详情
    handleButtonClick(row) {
      this.$refs.rzXq.handleOpen(row);
    },
    //查询进度
    handleJinDu(row) {
      this.$refs.picture.handleOpen(row);
    },
    //点击行 选中行
    clickRow(row) {
      this.selectedRow = row; // 更新选中的行
      const table = this.$refs.table;
      const selectedRows = table.selection;

      // 否则取消之前选中的行，并选中当前点击的行
      selectedRows.forEach(selectedRow => {
        table.toggleRowSelection(selectedRow);
      });
      table.toggleRowSelection(row);
    },
    /** 自定义序号 */
    indexMethod(index) {
      let pageNum = this.queryParams.pageNum - 1;
      if ((pageNum !== -1 && pageNum !== 0)) {
        return (index + 1) + (pageNum * this.queryParams.pageSize);
      } else {
        return (index + 1)
      }
    },
    /** 查询软著申请列表 */
    getList() {
      this.loading = true;
      listRzsq(this.queryParams).then(response => {
        this.rzsqList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        rzsqId: this.getRzSqId,
        nd: new Date().getFullYear(),
        rjName: null,
        zzqr: '中国水利水电第五工程局有限公司',
        zyWcR: null,
        kjryId: null,
        bcYy: null,
        kfFs: '独立开发',
        sqDw: null,
        xmsbId: null,
        kyXm: null,
        zygnJstd: null,
        idWhere: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        userId: null,
        deptId: null
      };
      this.rzglRzsqFjList = [];
      this.resetForm("formDialog");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      let ids = selection.map(item => item.rzsqId)
      if (ids.length === 1) {
        this.ids = ids[0]
      } else {
        this.ids = ids
      }
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('rzgl/rzsq/export', {
        ...this.queryParams
      }, `rzsq_${new Date().getTime()}.xlsx`)
    },
  }
};
</script>
